package net.taviscaron.drivenotes.api.action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.taviscaron.drivenotes.api.ResponseUtil;
import net.taviscaron.drivenotes.shared.model.entity.Place;
import net.taviscaron.drivenotes.shared.model.entity.User;
import net.taviscaron.drivenotes.shared.service.PlaceService;
import net.taviscaron.drivenotes.web.core.Constants;
import org.springframework.beans.factory.annotation.Required;

/**
 * Places action
 * @author Andrei Senchuk
 */
public class PlacesAction implements ApiAction {
    private PlaceService placeService;

    @Required
    public void setPlaceService(PlaceService placeService) {
        this.placeService = placeService;
    }

    public Object execute (HttpServletRequest request, HttpServletResponse response) {
        User user = (User) request.getAttribute(Constants.AUTHORIZED_USER_ATTR_NAME);
        List<Place> places = placeService.findPlacesByUser(user);
        return ResponseUtil.successResponse("places", places);
    }
}
